package com.arsn.myf.business.controller;

import com.arsn.myf.business.entity.Notice;
import com.arsn.myf.business.service.NoticeService;
import com.arsn.myf.business.vo.NoticeVO;
import com.arsn.myf.common.util.result.Func;
import com.arsn.myf.common.util.result.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wildfly.common.annotation.NotNull;
import java.util.Arrays;

/**
 * 公告控制器
 * @author zhongrj
 * @since 2022-11-28
 */
@RestController
@RequestMapping("/notice")
@AllArgsConstructor
@Api(value = "公告控制器", tags = "公告控制器")
public class NoticeController {

    private final NoticeService noticeService;

    /**
     * 查询公告的分页数据
     * @param page
     * @param notice
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询公告的分页数据")
    public R list(Page<Notice> page, Notice notice){
        return R.data(noticeService.page(page,new QueryWrapper<>(notice)));
    }

    /**
     * 自定义查询公告的分页数据
     * @param page
     * @param notice
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "自定义查询公告的分页数据")
    public R page(Page<NoticeVO> page, NoticeVO notice){
        return R.data(noticeService.selectPageNoticeList(page,notice));
    }

    /**
     * 公告详情信息
     * @param notice
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value = "公告详情信息")
    public R detail(Notice notice){
        return R.data(noticeService.getOne(new QueryWrapper<>(notice)));
    }

    /**
     * 公告新增
     * @param notice
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "公告新增")
    public R save(@RequestBody Notice notice){
        return R.status(noticeService.save(notice));
    }

    /**
     * 公告修改
     * @param notice
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "公告修改")
    public R update(@RequestBody Notice notice){
        return R.status(noticeService.updateById(notice));
    }

    /**
     * 删除,批量删除
     * @param ids
     * @return
     */
    @PostMapping("/remove")
    @ApiOperation(value = "删除,批量删除")
    public R remove(@NotNull String ids){
        return R.status(noticeService.removeByIds(Func.stringToLong(Arrays.asList(ids.split(",")))));
    }
}
